import datetime
from django.contrib.sites.models import Site
from django.db import models
from django.db.models import permalink
from django.utils.translation import ungettext, ugettext_lazy as _

class NewsPublManager(models.Manager):
    def get_query_set(self):
        return super(NewsPublManager, self).get_query_set().\
            filter(pub_date__lte=datetime.date.today())

class News(models.Model):
    site = models.ForeignKey(Site)
    headline = models.CharField(_('headline'), max_length=100)
    slug = models.SlugField(_('slug'), max_length=100, unique=True)
    content = models.TextField(_('content'))
    pub_date = models.DateField(_('publishing date'), default=datetime.date.today)

    objects = models.Manager()
    publ = NewsPublManager()

    def __unicode__(self):
        return self.headline

    @permalink
    def get_absolute_url(self):
        return ('news', (), {'slug': self.slug, })

    class Meta:
        verbose_name = ungettext('news', 'news', 1)
        verbose_name_plural = ungettext('news', 'news', 2)
        ordering = ('-pub_date',)
